package testtiles.object;

import java.util.LinkedList;

import butines.core.game.Image;
import butines.core.game.ImageSheet;
import butines.game.Sprite;

public class UnitTemplate {

	private String name;
	private int maxHealth;
	private float maxSpeed;
	private float mass;
	private float maxForce;
	private float viewDistance;
	private float radius;

	private int numAngles;
	private ImageSheet imageSheet;
	private AnimModel animWalk;
	private AnimModel animStay;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ImageSheet getImageSheet() {
		return imageSheet;
	}

	public void setImageSheet(ImageSheet imageSheet) {
		this.imageSheet = imageSheet;
	}
	
	public void setImageSheet(Image image, int width, int height) {
		this.imageSheet = new ImageSheet(image, width, height);
	}
	
	public int getMaxHealth() {
		return maxHealth;
	}

	public void setMaxHealth(int maxHealth) {
		this.maxHealth = maxHealth;
	}

	public float getMaxSpeed() {
		return maxSpeed;
	}

	public void setMaxSpeed(float maxSpeed) {
		this.maxSpeed = maxSpeed;
	}

	public float getMass() {
		return mass;
	}

	public void setMass(float mass) {
		this.mass = mass;
	}

	public float getMaxForce() {
		return maxForce;
	}

	public void setMaxForce(float maxForce) {
		this.maxForce = maxForce;
	}

	public float getViewDistance() {
		return viewDistance;
	}

	public void setViewDistance(float viewDistance) {
		this.viewDistance = viewDistance;
	}

	public float getRadius() {
		return radius;
	}

	public void setRadius(float radius) {
		this.radius = radius;
	}
	
	private class AnimModel {
		String name;
		boolean loop;
		float duration;
		int[] frames;
		public AnimModel(String name, boolean loop, float duration, int ... frames) {
			this.name = name;
			this.loop = loop;
			this.duration = duration;
			this.frames = frames;
		}
	}
	
	private LinkedList<AnimModel> animModelList = new LinkedList<UnitTemplate.AnimModel>();

	public void addAnimation(String name, boolean loop, float duration, int ... frames) {
		animModelList.add(new AnimModel(name, loop, duration, frames));
	}
	
	public Sprite createSprite() {
		Sprite sprite = new Sprite(imageSheet, numAngles);
		for (AnimModel am: animModelList) {
			sprite.newAnim(am.name).set(am.loop, am.duration, am.frames);
		}
		return sprite;
	}
	
}